//
//  RCNetRequestManager.m
//  RCNetRequestProject
//
//  Created by kabu on 2017/7/18.
//  Copyright © 2017年 RC. All rights reserved.
//

#import "RCHttpRequest.h"
@interface RCHttpRequest()
//@property (strong, nonatomic) RCReachability *reachability;
@end
@implementation RCHttpRequest
- (instancetype)init{
    self = [super init];
    if (self) {
        
    }
//    self.reachability = [RCReachability reachabilityWithHostName:@"https://www.baidu.com"];
    
    return self;
}
+ (instancetype)manager{
    return [[self alloc]init];
}
- (id<RCURLRequestSerialization>)requestSerialization{
    if (_requestSerialization) {
        return _requestSerialization;
    }
    return [RCHttpRequestSerialization serializer];
}
-(id<RCURLResponseSerialization>)responseSerialization{
    if (_responseSerialization) {
        return _responseSerialization;
    }
    return [RCHttpResponseSerialization serializer];
}
//- (NetworkStatus)netWorkStatusOfUrl:(NSString*)url{
//    if (url) {
//        self.reachability=[RCReachability reachabilityWithHostName:url];
//    }
//    return self.reachability.currentReachabilityStatus;
//}
- (NSTimeInterval)timeoutInterval{
    RCHttpRequestSerialization *httpReqSerialization=(RCHttpRequestSerialization*)self.requestSerialization;
    if (!httpReqSerialization.timeoutInterval) {
        httpReqSerialization.timeoutInterval=20;
    }
    return httpReqSerialization.timeoutInterval;
}
-(void)setTimeoutInterval:(NSTimeInterval)timeoutInterval{
    RCHttpRequestSerialization *httpReqSerialization=(RCHttpRequestSerialization*)self.requestSerialization;
    httpReqSerialization.timeoutInterval=timeoutInterval;
}
- (void)setValue:(NSString*)value forHTTPHeaderField:(NSString *)field{
    RCHttpRequestSerialization *httpReq=self.requestSerialization;
    
    [httpReq setValue:value forHttpHeader:field];
}

- (id)responseObjectForResponseSerialization:(NSURLResponse*)response data:(NSData*)data error:(NSError * __autoreleasing *)error{
    id resultObj=[self.responseSerialization responseObjectForResponseSerialization:response data:data error:error];
    if (*error) {
        return  data;
    }
    return  resultObj;
}
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method URLString:(NSString *)URLString parameters:(id)parameters error:(NSError * __autoreleasing *)error{
    RCHttpRequestSerialization *httpReqSerialization=(RCHttpRequestSerialization*)self.requestSerialization;
    NSMutableURLRequest *mutableRequest= [httpReqSerialization requestWithMethod:method URLString:URLString parameters:parameters error:error];
    return mutableRequest;
}
- (NSData*)serverCerData{
    return nil;
}
/**
 BaseURL
 
 @return 基础url
 */
- (NSString*)serverHostUrl{
    return @"http://www.youedata.cn";
}
#pragma mark RCNetRequest
- (id)getWithUrl:(NSString *)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
- (id)postWithUrl:(NSString *)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
- (id)putWithUrl:(NSString *)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
- (id)deleteWithUrl:(NSString *)url params:(id)params success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
- (id)downloadWithUrl:(NSString *)url params:(id)params atLocal:(NSURL *)aLocal success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
- (id)uploadWithUrl:(NSString *)url params:(id)params withLocal:(NSURL *)wLocal success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    
    return nil;
}
-(id)postWithUrl:(NSString *)url params:(id)params formData:(NSData*)aFormData mimeType:(NSString*)mimeType fileName:(NSString*)fileName name:(NSString*)name success:(RCNetRequestSuccessBlock)aSuccess failure:(RCNetRequestFailureBlock)aFailure{
    return nil;
}
@end
